package com.qf.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.qf.entity.OccupancyInfo;
import com.qf.entity.OccupancyInfoDTO;
import com.qf.service.OccupancyInfoService;
import com.qf.util.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * @ClassName: OccupancyInfoController
 * @Author: WangHao
 * @Date: 2025/4/28 15:42
 * @Description:
 * @Version: 1.0
 */
@RestController
@RequestMapping("/occupancyInfo")
public class OccupancyInfoController {

    @Autowired
    private OccupancyInfoService occupancyInfoService;

    // 分页查询
    @PostMapping("/findAll")
    public R findAll(@RequestBody OccupancyInfoDTO occupancyInfoDTO) {
        PageHelper.startPage(occupancyInfoDTO.getPageNum(), occupancyInfoDTO.getPageSize());
        List<OccupancyInfo> list = occupancyInfoService.findAll(occupancyInfoDTO);
        PageInfo<OccupancyInfo> pageInfo = new PageInfo<>(list);
        return R.ok(pageInfo);
    }

    // 删除
    @GetMapping("/delOccupancyInfoById")
    public R delOccupancyInfoById(Integer id) {
        boolean op = occupancyInfoService.delOccupancyInfoById(id);
        if (!op) {
            return R.fail();
        }
        return R.ok();
    }
    // 批量删除
    @GetMapping("/delOccupancyInfoBatch")
    public R delOccupancyInfoByIds(Integer[] ids) {
        boolean op = occupancyInfoService.delOccupancyInfoByIds(ids);
        if (!op) {
            return R.fail();
        }
        return R.ok();
    }

    // 退房
    @GetMapping("/updateLeaveTime/{id}")
    public R updateLeaveTime(@PathVariable Integer id) {
        boolean op = occupancyInfoService.updateLeaveTime(id);
        if (!op) {
            return R.fail();
        }
        return R.ok();
    }
}
